package sg4c.frontend.command;

import java.io.IOException;
import sg4c.frontend.GraphicsContext;
import sg4c.protocol.DataInputProtocol;

public class DrawLine implements GraphicsCommand {

    
    private final int startx;
    private final int starty;
    private final int endx;
    private final int endy;

    public DrawLine(int x1, int y1, int x2, int y2) {
        startx = x1;
        starty = y1;
        endx = x2;
        endy = y2;
    }

    public void execute(GraphicsContext context) {
        if (!context.noStroke()) {
            context.loadStrokeColor();
            context.getGraphics().drawLine(startx, starty, endx, endy);
        }
    }
    public static final Factory factory = new Factory() {

        public GraphicsCommand parse(DataInputProtocol in) throws IOException {
            int x1 = in.readInt();
            int y1 = in.readInt();
            int x2 = in.readInt();
            int y2 = in.readInt();
            return new DrawLine(x1, y1, x2, y2);
        }
    };
}
